#ifndef _LEXER_H_
#define _LEXER_H_

#include <string>

using namespace std;

#include "error.h"
#include "token.h"

class Lexer {
public:
    const char EOFF = 0;
protected:
    string input;   // 输入字符串
    int i = 0;      // 当前字符的索引
    char c;         // 当前字符
public:
    Lexer(string input) {
        this->input = input;
        c = input[i];
    }

    void consume() {
        advance();
        WS();
    }

    void advance() {
        i++;
        if (i >= input.size())
            c = EOFF;
        else
            c = input[i];
    }

    void match(char x) {
        if (c == x)
            consume();
        else {
            string s = "expecting ";
            s.push_back(x);
            s += "; found ";
            s.push_back(c);
            throw Error(s);
        }
    }

    virtual Token *next_token() = 0;
    virtual void WS() = 0;
    virtual string get_token_name(int x) = 0;
};

#endif
